import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class AdDialogPage extends StatelessWidget {
  const AdDialogPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Demo')),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showDialog(
              barrierDismissible: false,
              context: context,
              builder:(context) {
                return UnconstrainedBox(
                  child: SizedBox(
                    height: 300,
                    child: Stack(
                      alignment: Alignment.center,
                      children: [
                        Image.asset(
                          'assets/images/previewed.png',
                          fit: BoxFit.cover,
                          width: 250,
                          height: 250,
                        ),
                        Positioned(
                          top: 0,
                          right: 0,
                          child: GestureDetector(
                            onTap: () {
                              if (kDebugMode) {
                                print('!!!!');
                              }
                              Navigator.of(context).pop();
                            },
                            child: DecoratedBox(
                              decoration: BoxDecoration(
                                border: Border.all(
                                  color: Colors.white54,
                                  width: 1.0
                                ),
                                borderRadius: const BorderRadius.all(Radius.circular(16))
                              ),
                              child: const Icon(Icons.close, color: Colors.white54,)
                            )
                          ),
                        ),
                      ],
                    )
                  )
                );
              }
            );
          },
          child: const Text("打开Dialog"),
        )
      ),
    );
  }
}